package com.hive.decode;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Demo {

    public static void main(String[] args) throws Exception {

        Connection conn = HiveConn.getConn();
        Statement statement = conn.createStatement();

        String sql = toArrayByFileReader1("F:\\tmp\\hive\\历史安装人群_20200918_02.txt");
        sql = "select * from tools.dmn_hkdw_dbp_md5_cn  where hkdw_md5_dbp in (" + sql + ")";

        List<String> list = new ArrayList<String>();
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            String a = resultSet.getString(1);
//            String end = HKEncryUtil.decrypt(a);
            String end = "HKEncryUtil.decrypt(a)";
            list.add(end);
        }
        FileUtils.writeFileLine("F:\\tmp\\hive\\历史安装人群_20200918_02_result.txt","utf-8",list);

        HiveConn.close(conn);
    }


    public static String toArrayByFileReader1(String name) {

        // 使用ArrayList来存储每行读取到的字符串
        StringBuilder stringBuilder = new StringBuilder();
        try {
            FileReader fr = new FileReader(name);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                stringBuilder.append(str);
            }
            bf.close();
            fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 对ArrayList中存储的字符串进行处理

        // 返回数组
        return stringBuilder.toString();
    }

}